<app-content-header
  [search]="search"
  [showSearch]="ifShowSearch"
  [action]="aclService.canAbility('api.post.camel.terminal.one') && action"
  (actionClick)="goNew()"
>
  <ng-template #search>
    <app-search [(data)]="searchSchema" [customItems]="customSchema" (bindSearch)="handleSearch()"></app-search>
  </ng-template>

  <ng-template #action> <i nz-icon type="plus"></i> {{ 'BTN.ADD' | translate }} </ng-template>
</app-content-header>

<div class="cil-table-block">
  <st
    #st
    [scroll]="scroll"
    [data]="data"
    [columns]="columns"
    [widthMode]="widthMode"
    [ps]="ps"
    [pi]="pi"
    [page]="stPage"
    [total]="total"
    [loading]="loading"
    (change)="onChange($event)"
  >
    <ng-template st-row="cdKey" let-item let-index="index" let-column="column">
      <span nz-popover [nzContent]="contentTemplate" nzPlacement="right">{{ item.common.cdKey }}</span>
      <ng-template #contentTemplate>
        <qrcode [qrdata]="item.common.cdKey" [size]="200" [level]="'M'"> </qrcode>
      </ng-template>
    </ng-template>
    <ng-template st-row="status" let-item>
      <span>{{ StatusTextMapForTerminal[item.common.status] | i18n }}</span>
    </ng-template>
  </st>
  <div *ngIf="!loading" #btns class="cil-custom-btns">
    <button
      class="cil__custom-btn__lightblue"
      nz-button
      nzType="primary"
      nzShape="round"
      nzSize="default"
      (click)="exportAll()"
      acl
      [acl-ability]="'api.get.camel.terminals.report'"
    >
      <i nz-icon type="download"></i>
      {{ 'BTN.EXPORT' | i18n }}
    </button>
  </div>
</div>

<ng-template #tplAcquirer>
  <app-aams-select
    level="institution"
    [(ngModel)]="selectedAcquirer"
    [disabled]="isAcquirerUser"
    (valueChange)="aamsChangeHandler($event)"
  ></app-aams-select>
</ng-template>

<ng-template #tplGroup>
  <app-aams-select
    level="agent"
    [(ngModel)]="selectedGroup"
    [insCode]="selectedAcquirer ? selectedAcquirer.code : ''"
    [disabled]="isAgentUser"
    (valueChange)="aamsChangeHandler($event)"
  ></app-aams-select>
</ng-template>

<ng-template #tplMerchant>
  <app-aams-select
    level="merchant"
    [(ngModel)]="selectedMerchant"
    [insCode]="selectedAcquirer ? selectedAcquirer.code : ''"
    [agentCode]="selectedGroup ? selectedGroup.code : ''"
    [disabled]="isMerchantUser"
    (valueChange)="aamsChangeHandler($event)"
  ></app-aams-select>
</ng-template>

<ng-template #tplStore>
  <app-aams-select
    level="store"
    [(ngModel)]="selectedStore"
    [insCode]="selectedAcquirer ? selectedAcquirer.code : ''"
    [agentCode]="selectedGroup ? selectedGroup.code : ''"
    [intMerCode]="selectedMerchant ? selectedMerchant.code : ''"
    [disabled]="isStoreUser"
    (valueChange)="aamsChangeHandler($event)"
  ></app-aams-select>
</ng-template>
